package classes.view.component
{
	import flash.display.MovieClip;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	public class PenaltyClock extends MovieClip
	{
		
		private const PENALTY_DURATION : int = 5; //페널티 시간
		private var timer : Timer; 
		private var currTime :int; 
		
		public function PenaltyClock()
		{
			super();
			currTime = PENALTY_DURATION; 
			this.gotoAndStop(PENALTY_DURATION.toString(10)); 
			timer = new Timer(1000, PENALTY_DURATION); 
			timer.addEventListener(TimerEvent.TIMER, onTickHandler);
			timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerCompleteHandler); 
		}
		
		private function onTickHandler(event : TimerEvent):void
		{
			currTime--; 
			this.gotoAndStop(currTime.toString(10));
			
		}
		
		private function onTimerCompleteHandler(event : TimerEvent):void
		{
			hide(); 
			dispatchEvent(new GameEvent(GameEvent.PENALTY_OVER)); 
		}
		
		public function hide():void
		{
			timer.reset();
			timer.stop();
			
			this.visible = false;
			this.gotoAndStop(PENALTY_DURATION.toString(10)); 
			currTime = PENALTY_DURATION;
		}
		
		public function show():void
		{
			this.visible = true;
			timer.reset();
			timer.start();
		}
	}
}